# -*- coding: utf-8 -*-
import os
import sys

import aircv as ac


def match_pic(img_source, img_target):
    """
    match template
    """
    imsrc = ac.imread(img_source)
    imobj = ac.imread(img_target)
    pos = ac.find_template(imsrc, imobj, rgb=True, bgremove=True)
    if not pos:
        return None, None, None

    top_left = pos['rectangle'][0]  # 左上
    right_bottom = pos['rectangle'][3]  # 右下
    circle_center_pos = pos['result']  # 中心点坐标
    circle_center_pos = tuple(map(int, circle_center_pos))
    print('准确率:', pos['confidence'])
    print(circle_center_pos)  # 坐标位置
    return circle_center_pos, top_left, right_bottom


if __name__ == "__main__":
    img_source = sys.path[0] + '/t001.png'
    img_target = sys.path[0] + '/t01.png'
    circle_center_pos, top_left, right_bottom = match_pic(img_source, img_target)
    print(circle_center_pos[0])

    print(sys.path[0])
    # print(sys.argv)
